package com.allen.app.common.config.redis;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import lombok.Data;
import org.redisson.spring.cache.CacheConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;

@Data
@ConfigurationProperties(prefix = RedissonProperties.PREFIX)
public class RedissonProperties {

    public static final String PREFIX = "microx.redisson";

    private RedisServerMode serverMode = RedisServerMode.SINGLE;

    private List<String> addresses = new ArrayList<>(0);

    private Map<String, CacheConfig> caches;

    private int timeout = 3000;

    private String password;

    private int connectionPoolSize = 64;

    private int connectionMinimumIdleSize = 10;

    private SentinelServers sentinelServers;

    private int database = 0;

    @Data
    public static class SentinelServers {

        private String masterName;

        private int slaveConnectionPoolSize = 250;

        private int masterConnectionPoolSize = 250;
    }

    public void setAddresses(String addresses) {
        String[] array = StringUtils.tokenizeToStringArray(addresses, ",;");
        this.addresses = Arrays.asList(array);
    }
}
